package com.hy.service.impl;

import com.hy.bean.Discuss;
import com.hy.dao.CommentDao;
import com.hy.service.CommentService;
import com.hy.utils.ResponseResult;
import com.hy.utils.ResultUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

public class CommentServiceImpl implements CommentService {
    private CommentDao commentDao = new CommentDao();

    //添加喜欢
    @Override
    public void saveDiscuss(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer userId = Integer.valueOf(request.getParameter("userId"));
        Integer commentId =  Integer.valueOf(request.getParameter("commentId"));
        Discuss discuss = new Discuss();
        discuss.setUserId(userId);
        discuss.setCommentId(commentId);
        discuss.setCreateId(userId);
        boolean flag = commentDao.insertDiscuss(discuss);
        ResponseResult<?> result = new ResponseResult<>(200, "数据", flag, 101);
        ResultUtils.result(result, request, response);
    }
    //查找喜欢数量
    @Override
    public void getDiscussCount(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer commentId = Integer.valueOf(request.getParameter("commentId"));
        Long count= commentDao.selectDiscussCount(commentId);
        ResponseResult<?> result = new ResponseResult<>(200, "数据", count, 101);
        ResultUtils.result(result, request, response);
    }
    //查找自己的账号的喜欢
    @Override
    public void getDiscuss(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer userId = Integer.valueOf(request.getParameter("userId"));
        Integer commentId = Integer.valueOf(request.getParameter("commentId"));
        Discuss discuss = commentDao.selectDiscuss(userId,commentId);

        ResponseResult<?> result = new ResponseResult<>(200, "数据", discuss, 101);
        ResultUtils.result(result, request, response);
    }
    //修改评论表逻辑删除
    @Override
    public void updateTombstone(HttpServletRequest request, HttpServletResponse response) throws Exception{
        Integer id = Integer.valueOf(request.getParameter("commentId"));
        String tombstone = request.getParameter("tombstone");

        boolean flag = commentDao.updateTombstone(id,tombstone);
        ResponseResult<?> result = new ResponseResult<>(200, "数据", flag, 101);
        ResultUtils.result(result, request, response);
    }
}
